/*package com.utils.spring.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import lombok.extern.slf4j.Slf4j;

*//**
 * 数据库配置
 * @author ty
 * @see http://stackoverflow.com/questions/18649583/jpa-provider-vs-dialect-vs-vendor-in-the-spring-contaniner-configuration
 *//*
@Configuration
@EnableJpaRepositories(
        basePackages = { "com.kyhd.audio.dao"},
        entityManagerFactoryRef = "entityManager", transactionManagerRef = "transactionManager")
@Import(PropertyConfig.class)
@EnableTransactionManagement
@Slf4j
public class JPAConfiguration {

    @Value("${jdbc.driverclass}")
    private String driverClassName;

    @Value("${jdbc.url}")
    private String url;

    @Value("${jdbc.username}")
    private String username;

    @Value("${jdbc.password}")
    private String password;

    @Value("${hibernate.sql.dialect}")
    String hibernameSqlDialect;

    @Value("${hibernate.sql.generateddl}")
    Boolean hibernateGenerateDdl;

    @Value("${hibernate.sql.show}")
    Boolean hibernateShowSql;

    private boolean isUsernameEmpty() {
        return this.username == null || this.username.isEmpty() || "${jdbc.username}".equals(this.username);
    }

    private boolean isPasswordEmpty() {
        return this.password == null || this.password.isEmpty() || "${jdbc.password}".equals(this.password);
    }

    @Bean(destroyMethod = "close")
    @Primary
    public DataSource dataSource() {
        // EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
        // return builder.setType(EmbeddedDatabaseType.HSQL).build();

        if (log.isDebugEnabled()) {
            log.debug("driverClassName: {}, url: {}", this.driverClassName, this.url);
            log.debug("username empty: {}", this.isUsernameEmpty());
            log.debug("password empty: {}", this.isPasswordEmpty());
        }

        final org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource();
        dataSource.setDriverClassName(this.driverClassName);
        dataSource.setUrl(this.url);
        dataSource.setUsername(!this.isUsernameEmpty() ? this.username : "");
        dataSource.setPassword(!this.isPasswordEmpty() ? this.password : "");
        dataSource.setInitialSize(50);
        dataSource.setMaxActive(200);
        dataSource.setMaxIdle(5);
        dataSource.setMinIdle(5);
        dataSource.setMaxWait(500);
        // dataSource.setValidationQuery("SELECT 1 FROM SYSIBM.SYSDUMMY1");
        dataSource.setValidationQuery("SELECT 1");
        dataSource.setTestOnBorrow(true);
        dataSource.setTestOnReturn(true);
        dataSource.setTestWhileIdle(true);
        // test pool miss
        dataSource.setLogAbandoned(true);
        dataSource.setRemoveAbandoned(true);
        dataSource.setRemoveAbandonedTimeout(60 * 60);

        dataSource.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;" +
                "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");

        return dataSource;
    }

    //	@Bean(name = "jpaVendorAdapter")
    private JpaVendorAdapter jpaVendorAdapter() {

        if (log.isDebugEnabled()) {
            log.debug("sqlDialect: {}, generateDdl: {}, showSql: {}", hibernameSqlDialect, hibernateGenerateDdl, hibernateShowSql);
        }

        final HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
        adapter.setDatabasePlatform(hibernameSqlDialect);
        adapter.setGenerateDdl(hibernateGenerateDdl);
        adapter.setShowSql(hibernateShowSql);
        return adapter;
    }

    @Bean
    @Primary
    public LocalContainerEntityManagerFactoryBean entityManager() {

        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        factory.setJpaVendorAdapter(jpaVendorAdapter());
        // factory.setPackagesToScan("com.");
        factory.setDataSource(dataSource());
        factory.setPersistenceUnitName("default-persistence-unit");
        factory.afterPropertiesSet();

        return factory;
    }

    @Bean
    @Primary
    public PlatformTransactionManager transactionManager() {

        JpaTransactionManager txManager = new JpaTransactionManager();
        txManager.setEntityManagerFactory(entityManager().getObject());
        return txManager;
    }

}
*/